import java.util.Scanner;

public class Main {
    public static int BitSum(int n) {
        int sum = 0;
        while (n>0) {
            int t=n%10;
            sum+=t*t;
            n=n/10;
        }
        return sum;
    }
    public static boolean Happy(int num) {
        int slow=num,fast=BitSum(num);//定义快慢指针，快指针指向当前值的平方和 例如19=1^2+9^2...
        while (slow!=fast) {
            slow=BitSum(slow);
            fast=BitSum(BitSum(fast));
        }
        return slow==1;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        if(Happy(n)){
            System.out.println("True");
        }else{
            System.out.println("False");
        }
    }
}
